package com.alibaba.cloudalibabaserver.repository;


import com.alibaba.cloudalibabaserver.bean.Order;
import com.alibaba.cloudalibabaserver.bean.OrderDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrderRepository extends JpaRepository<Order, Long> {

    /**
     * 根据用户ID查询订单
     */
    List<Order> findByUserId(Long userId);

    /**
     * 根据用户ID和订单状态查询
     */
    List<Order> findByUserIdAndOrderStatus(Long userId, Integer orderStatus);

    /**
     * 根据用户ID范围查询
     */
    List<Order> findByUserIdBetween(Long startUserId, Long endUserId);

    /**
     * 自定义查询：根据订单金额大于指定值查询
     */
    @Query("SELECT o FROM Order o WHERE o.orderAmount > :amount")
    List<Order> findOrdersByAmountGreaterThan(@Param("amount") Double amount);

    /**
     * 统计用户订单数量
     */
    Long countByUserId(Long userId);
}